package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.User_ManagementService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user_management")
public class user_management {
    @Reference
    private User_ManagementService user_managementService;
    //分页查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean pageBean){
        return user_managementService.findPage(pageBean);
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        try{
            List<Role> list = user_managementService.findAll();//发送请求
            return new Result(true, MessageConstant.TEST_1,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.TEST_2);
        }
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody Role Role, Integer[] checkitemIds){
        try{
            user_managementService.edit(Role,checkitemIds);//发送请求
            return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKITEM_FAIL);
        }
    }
    @RequestMapping("/add")
    public Result add(@RequestBody User user){
        try {
            user_managementService.add(user);
            return new Result(true, "添加用户成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加用户失败！");
        }
    }
}

